Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • List files*in a directory that do not end with a suffix

    Hi Stata users,

    I have dta files at both household and individual levels in the same folder with the difference in names being individual level dataset having the suffix p e.g ba03 and ba03p. I am wondering whether it's possible to tweek the command below to list files that do not end with p

    Code:
    local files : dir "`MICSdir'" files "*.dta"
    Thanks in advance!


  • #2
    You can't directly tweak the command below, but you can get what you want in several other ways. The example below demonstrates my preferred technique, but it does rely on your household file names never ending in p.
    Code:
    . dir demo
    
    total 128
    -rw-r--r--  1 lisowskiw  staff  12765 Jan  2 09:14 ba03.dta
    -rw-r--r--  1 lisowskiw  staff  12765 Jan  2 09:14 ba03p.dta
    -rw-r--r--  1 lisowskiw  staff  12765 Jan  2 09:15 bzxx.dta
    -rw-r--r--  1 lisowskiw  staff  12765 Jan  2 09:15 bzxxp.dta
    
    . local files : dir "demo" files "*.dta"
    
    . local ind   : dir "demo" files "*p.dta"
    
    . local hh    : list files - ind
    
    . macro list _files _ind _hh
    _files:         "bzxxp.dta" "bzxx.dta" "ba03p.dta" "ba03.dta"
    _ind:           "bzxxp.dta" "ba03p.dta"
    _hh:            "bzxx.dta" "ba03.dta"
    
    .

    Comment


    • #3
      Thanks a bunch William Lisowski for the great solution. Much appreciated.

      Comment

      Working...
      X